package com.osce.score.controller;

import com.csce.domain.entity.score.ScoreSkill;
import com.osce.common.annotation.Log;
import com.osce.common.core.controller.BaseController;
import com.osce.common.core.entity.AjaxResult;
import com.osce.common.core.page.TableDataInfo;
import com.osce.common.enums.BusinessType;
import com.osce.common.utils.poi.ExcelUtil;
import com.osce.interfaces.score.IScoreSkillService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 技能管理Controller
 *
 * @author zzx
 * @since 2023-08-21
 */
@RestController
@RequestMapping("/score/skill")
public class ScoreSkillController extends BaseController {

    @Resource
    private IScoreSkillService scoreSkillService;

    /**
     * 查询技能管理列表
     */
    @PreAuthorize("@ss.hasPermi('score:skill:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScoreSkill scoreSkill) {
        startPage();
        List<ScoreSkill> list = scoreSkillService.selectScoreSkillList(scoreSkill);
        return getDataTable(list);
    }

    /**
     * 导出技能管理列表
     */
    @PreAuthorize("@ss.hasPermi('score:skill:export')")
    @Log(title = "技能管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScoreSkill scoreSkill) {
        List<ScoreSkill> list = scoreSkillService.selectScoreSkillList(scoreSkill);
        ExcelUtil<ScoreSkill> util = new ExcelUtil<ScoreSkill>(ScoreSkill.class);
        util.exportExcel(response, list, "技能管理数据");
    }

    /**
     * 获取技能管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('score:skill:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(scoreSkillService.selectScoreSkillById(id));
    }

    /**
     * 新增技能管理
     */
    @PreAuthorize("@ss.hasPermi('score:skill:add')")
    @Log(title = "技能管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScoreSkill scoreSkill) {
        return toAjax(scoreSkillService.insertScoreSkill(scoreSkill));
    }

    /**
     * 修改技能管理
     */
    @PreAuthorize("@ss.hasPermi('score:skill:edit')")
    @Log(title = "技能管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScoreSkill scoreSkill) {
        return toAjax(scoreSkillService.updateScoreSkill(scoreSkill));
    }

    /**
     * 删除技能管理
     */
    @PreAuthorize("@ss.hasPermi('score:skill:remove')")
    @Log(title = "技能管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(scoreSkillService.deleteScoreSkillByIds(ids));
    }
}
